<?php

// ##############################################################################||
// #                                                                 
// #   MySmartBB Version 1.7.0	                                      
// #   http://www.MySmartBB.com                                      
// #   Copyright (c) 2008 by MySmartBB team                           
// #   license http://opensource.org/licenses/gpl-license.php GNU Public License
// #                                                             
// #   filename : usercp.php
// #   member's control panel
// #                                                                  
// ##############################################################################||

// ** General definitions **

     define('NOT_IN_INDEX',0);
     include('common.php');
     include('includes/pager.php');

 if ($member_permission == 1)
 {
         if ($_GET['index'] == 1)
         {
             $SF->html_title_page('لوحة التحكم الخاصه بـ ' . $member_row['username'] . ' - (Powered By MySmartBB Universal)');

             $lastreply_query = $DB->sql_query("SELECT DISTINCT subject_id FROM " . $db_prefix . "reply WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND delete_topic<>'1' AND keepmeon=1 ORDER BY id DESC LIMIT 0,10");
             $lastreply_num   = $DB->sql_num_rows($lastreply_query);

             if ($lastreply_num != 0)
             {
                 while ($lastreply_row = $DB->sql_fetch_array($lastreply_query))
                 {
                     $lastrsubject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . $lastreply_row['subject_id'] . "' AND delete_topic<>'1'");

                     if (!isset($lastrsubjects_row)){
                         $lastrsubjects_row = array();
                     }

                     while ($lastrsubject_row = $DB->sql_fetch_array($lastrsubject_query))
                     {
                         $lastrsubjects_row[] = $lastrsubject_row;
                         $Smarty->assign('lastrsubjects_row',$lastrsubjects_row);
                         if ($lastrsubject_row['reply_number'] > 0)
                         {
                             $reply_q = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE delete_topic<>'1' and subject_id='" . $lastrsubject_row['id'] . "' order by id DESC LIMIT 1");
                             $reply_r = $DB->sql_fetch_array($reply_q);

                             $reply_r2[] = $reply_r;
                             $Smarty->assign("reply_r2",$reply_r2);

                             $replier_q = $DB->sql_query("SELECT * FROM " . $db_prefix . "member where username='" . $reply_r['writer'] . "'");

                             $replier_r[] = $DB->sql_fetch_array($replier_q);
                             $Smarty->assign("replier_r",$replier_r);
                         }
                     }
                 }
             }
             else
             {
                 $Smarty->assign('NoReply',1);
             }


             $subject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND delete_topic<>'1' ORDER BY id DESC LIMIT 0,10");
             $subject_num   = $DB->sql_num_rows($subject_query);

             if ($subject_num != 0)
             {
                 $subjects_row = array();
                 while ($subject_row = $DB->sql_fetch_array($subject_query))
                 {
                     $subjects_row[] = $subject_row;
                     $Smarty->assign('subjects_row',$subjects_row);
                 }

             }
             else
             {
                 $Smarty->assign('NoSubject',1);
             }

             $Smarty->assign_by_ref('member_row',$member_row);

             $Smarty->display('usercp_menu.tpl');
             $Smarty->display('usercp_homepage.tpl');

             $SF->FastMove();

             $Smarty->display('footer.tpl');

             if ($_GET['note'] == 1)
             {
                 $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET user_notes='" . $SF->SafeSQL($_POST['S1']) . "' WHERE id='" . $member_row['id'] . "'");

                 if ($update)
                 {
                     $SF->go_to('usercp.php?index=1',0);
                 }
             }

         }

         if ($_GET['cp'] == 1)
         {
		 
		 
#------------------------------------------------
				$da = $_POST['da'];
				$ma = $_POST['ma'];
				$ya = $_POST['ya'];
				$ca = "$da/$ma/$ya";
				$sa = "$da/$ma";
				$Smarty->assign('sa',$sa);
				$Smarty->assign('da',$da);
				$Smarty->assign('ma',$ma);
				$Smarty->assign('ya',$ya);
				$Smarty->assign('ca',$ca);
#------------------------------------------------
				$d= date("j/n");
				$Smarty->assign('d',$d);
				
				$rec = $DB->sql_query("SELECT * FROM `" . $db_prefix . "member` WHERE bday ='$d'");
				
				while($row = $DB->sql_fetch_array($rec))
					{
						$BD[] = $row;
						$Smarty->assign('MBD', $BD);
					}
#------------------------------------------------			 
		 
		 
             if ($_GET['info'] == 1)
             {
		         $SF->html_title_page('معلوماتك الشخصية - (Powered By MySmartBB Universal)');
                 if ($_GET['main'] == 1)
                 {
                     include('includes/SmartCode.js');

                     $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");
                     $smiles_row = array();

                     while ($smile_row = $DB->sql_fetch_array($smiles_query))
                     {
                         $smiles_row[] = $smile_row;
                         $Smarty->assign('smiles_row',$smiles_row);
                     }

                     $away_msg = $member_row['away_msg'];
                     $away_msg = str_replace('>', '&gt;', $away_msg);
                     $away_msg = str_replace('<', '&lt;', $away_msg);


                     $Smarty->assign('away_msg',$away_msg);

                     $SF->GetSmartCode();

                     $Smarty->display('usercp_menu.tpl');
                     $Smarty->display('usercp_persnol-info.tpl');
					 $SF->FastMove();
                     $Smarty->display('footer.tpl');
                 }

                 if ($_GET['start'] == 1)
                 {
                     $away_set = 0;

                     if (!empty($_POST['S1']) and $_POST['D1'] == 1)
                     {
                         $away_msg = nl2br($_POST['S1']);
                         $away_set = 1;
                     }

                     if (!empty($_POST['S1']) and $_POST['D1'] == 0)
                     {
                         $away_msg = nl2br($_POST['S1']);
                         $away_set = 0;
                     }

                     if (empty($_POST['S1']))
                     {
                         $away_set = 0;
                     }

                     $website = $_POST['T2'];
                     $search  = strstr($website,'http://');

                     if(!$search)
					 {
						if($_POST['T2']=='')
						{
							$website = '';
						}
						else
						{
							$website = 'http://' . $_POST['T2'];
						}
					 }

                     $away = $SF->SafeSQL($_POST['S1']);
                     $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET user_country='" . $SF->SafeSQL($_POST['T1']) . "',user_website='" . $SF->SafeSQL($website) . "',user_info='" . $SF->SafeSQL($_POST['T3']) . "',away='" . $away_set . "',away_msg='" . $away . "' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");

                     if ($update)
                     {
						$Smarty->assign('msgg','تم تحديث معلوماتك بنجاح !'); 
						$Smarty->assign('GO','usercp.php?cp=1&info=1&main=1');
						$SF->go_to('usercp.php?cp=1&info=1&main=1',2);             
						$Smarty->display('loading.tpl');

                         $Smarty->display('footer.tpl');
                     }
                 }
             }

             if ($_GET['sig'] == 1)
             {
				 $SF->html_title_page('تحرير التوقيع - (Powered By MySmartBB Universal)');
                 include('includes/SmartCode.js');
                 if ($groupper_row['sig_allow'] == 0)
                 {
                     $SF->error('المعذرة، لا يمكنك استخدام التوقيع');
                 }

                 if ($_GET['main'] == 1)
                 {
                     $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");
                     $smiles_row = array();

                     while ($smile_row = $DB->sql_fetch_array($smiles_query))
                     {
                         $smiles_row[] = $smile_row;
                         $Smarty->assign('smiles_row',$smiles_row);
                     }

                     $sig = str_replace('<br />','',$member_row['user_sig']);
                     $show_sig = $member_row['user_sig'];
                     $show_sig = str_replace('>', '&gt;', $show_sig);
                     $show_sig = str_replace('<', '&lt;', $show_sig);

                     $show_sig = $SF->SmartCode_replace($show_sig);
                     $show_sig = $SF->SmilesReplace($show_sig);

                     $Smarty->assign('sig',$sig);
                     $Smarty->assign('show_sig',$show_sig);

                     $SF->GetSmartCode();

                     $Smarty->display('usercp_menu.tpl');
                     $Smarty->display('usercp_edit-sig.tpl');
			 		 $SF->FastMove();
                     $Smarty->display('footer.tpl');
                 }

                 if ($_GET['start'] == 1)
                 {

                     if ($groupper_row['sig_allow'] == 0)
                     {
                         $SF->error('المعذرة، لا يمكنك استخدام التوقيع');
                     }

                     if (strlen($_POST['S1']) > $groupper_row['sig_len'])
                     {
                         $SF->error('المعذرة، لقد تعديت الطول المسموح لك و هو ' . $groupper_row['sig_len'] . ' حرف');
                     }

                     $sig    = $_POST['S1'];
                     $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET user_sig='$sig' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");

                     if ($update)
                     {
						$Smarty->assign('msgg','حُرِّرَ التوقيع بنجاح'); 
						$Smarty->assign('GO','usercp.php?cp=1&sig=1&main=1');
						$SF->go_to('usercp.php?cp=1&sig=1&main=1',2);             
						$Smarty->display('loading.tpl');

                         $Smarty->display('footer.tpl');
                     }
                 }
             }

             if ($_GET['password'] == 1)
             {  
				$SF->html_title_page('تحرير كلمة المرور - (Powered By MySmartBB Universal)');
                 if ($_GET['main'] == 1)
                 {
                     $Smarty->display('usercp_menu.tpl');
                     $Smarty->display('usercp_password.tpl');
					 $SF->FastMove();
                     $Smarty->display('footer.tpl');
                 }

                 if ($_GET['start'] == 1)
                 {

                     $check = $DB->sql_query("SELECT * FROM " . $db_prefix . "member WHERE username='" . $SF->SafeSQL($member_row['username']) . "' AND password='" . md5($_POST['T1']) . "'");
                     if ($DB->sql_num_rows($check) <= 0)
                     {
                         $SF->error('المعذره كلمة المرور التي قمت بكتابتها غير صحيحه');
                     }

                     $url = "http://".$_SERVER["HTTP_HOST"]."".$_SERVER["REQUEST_URI"]."";
                     $url   = str_replace('usercp.php?cp=1&password=1&start=1','',$url);
                     $s     = $SF->random();
                     $url_g = $url . 'misc.php?new_password=1&m=' . $s;
                     $url_c = $url . 'misc.php?cancel_req=1&m=' . $s;

                     if (strlen(trim($_POST['T2'])) > $info_row['reg_pass_max_num'])
                     {
                         $SF->error('عدد حروف كلمة المرور أكبر من (' . $info_row['reg_pass_max_num'] . ')');
                     }

                     if ($_POST['T2'] != $_POST['T3'])
                     {
                         $SF->error('كلمتي المرور غير متطابقة' );
                     }


                     if (strlen(trim($_POST['T2'])) < $info_row['reg_pass_min_num'])
                     {
                         $SF->error('عدد حروف كلمة المرور أقل من (' . $info_row['reg_pass_min_num'] . ')');
                     }

                     $insert = $DB->sql_query("INSERT INTO " . $db_prefix . "requests(id,random_url,username,request_type ) VALUES('NULL','" . $s . "','" . $SF->SafeSQL($member_row['username']) . "','1')");

                     if ($insert)
                     {
                         $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET new_password='" . md5($_POST['T2']) . "' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");
                         if ($update)
                         {
                             if ($info_row['confirm_on_change_pass'] == 1 )
                             {
                                 $getmsg_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='1'");
                                 $getmsg_row   = $DB->sql_fetch_array($getmsg_query);

                                 $text = $getmsg_row['text'];
                                 $text = str_replace('[MySBB]username[/MySBB]',$member_row['username'],$text);
                                 $text = str_replace('[MySBB]change_url[/MySBB]',$url_g,$text);
                                 $text = str_replace('[MySBB]cancel_url[/MySBB]',$url_c,$text);
                                 $text = str_replace('[MySBB]board_title[/MySBB]',$info_row['title'],$text);

                                 $SF->mail($member_row['email'],$getmsg_row['title'],$text,$info_row['send_email']);
                                 $Smarty->assign('msgg','تم ارسال الرساله إلى بريدك الالكتروني , يرجى مراجعته');
                                 $url = 'usercp.php?cp=1&password=1&main=1';
                             }
                             else
                             {
                                 $url = $url_g;
                             }

 
               			  $Smarty->assign('GO',$url);
						  $SF->go_to($url,2);            
              			  $Smarty->display('loading.tpl');

                             $Smarty->display('footer.tpl');
                         }
                     }
                 }
             }

             if ($_GET['email'] == 1)
             { 
			 $SF->html_title_page('تحرير البريد الإلكتروني - (Powered By MySmartBB Universal)');
                 if ($_GET['main'] == 1)
                 {

                     $Smarty->display('usercp_menu.tpl');
                     $Smarty->display('usercp_email.tpl');
					 $SF->FastMove();
                     $Smarty->display('footer.tpl');
                 }

                 if ($_GET['start'] == 1)
                 {
                     $email_check   = explode('@',$_POST['T2']);
                     $mail_check    = $DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "member WHERE email='" . $_POST['T2'] . "'"));

                     if ($mail_check > 0)
                     {
                         $SF->error('المعذره .. البريد الالكتروني موجود مسبقاً');
                     }

                     if (count($email_check) == 1)
                     {
                         $SF->error('يرجى كتابة بريدك الصحيح !');
                     }
                     $T2 = $SF->SafeSQL($_POST['T2']);
                     $url = "http://".$_SERVER["HTTP_HOST"]."".$_SERVER["REQUEST_URI"]."";
                     $url   = str_replace('usercp.php?cp=1&email=1&start=1','',$url);
                     $s     = $SF->random();
                     $url_g = $url . 'misc.php?new_email=1&m=' . $s;
                     $url_c = $url . 'misc.php?cancel_req=1&m=' . $s;

                     $insert = $DB->sql_query("INSERT INTO " . $db_prefix . "requests(id,random_url,username,request_type) VALUES('NULL','" . $s . "','" . $SF->SafeSQL($member_row['username']) . "','2')");
                     if ($insert)
                     {
                         $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET new_email='" . $T2 . "' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");
                         if ($update)
                         {
                             if ($info_row['confirm_on_change_mail'] == 1 )
                             {
                                 $getmsg_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='2'");
                                 $getmsg_row   = $DB->sql_fetch_array($getmsg_query);

                                 $text = $getmsg_row['text'];
                                 $text = str_replace('[MySBB]username[/MySBB]',$member_row['username'],$text);
                                 $text = str_replace('[MySBB]change_url[/MySBB]',$url_g,$text);
                                 $text = str_replace('[MySBB]cancel_url[/MySBB]',$url_c,$text);
                                 $text = str_replace('[MySBB]board_title[/MySBB]',$info_row['title'],$text);

                                 $SF->mail($member_row['email'],$getmsg_row['title'],$text,$info_row['send_email']);

								 $Smarty->assign('msgg','تم ارسال الرساله إلى بريدك الالكتروني , يرجى مراجعته');
                                 $SF->msg();
                                 $url = 'usercp.php?cp=1&email=1&main=1';
                             }
                             else
                             {
                                 $url = $url_g;
                             }

               			  $Smarty->assign('GO',$url);
						  $SF->go_to($url,2);            
              			  $Smarty->display('loading.tpl');


                                 $Smarty->display('footer.tpl');
                         }
                     }
                 }
             }

             if ($_GET['avatar'] == 1)
             {
     			 $SF->html_title_page('تحرير الصورة الرمزية - (Powered By MySmartBB Universal)');
                 if ($info_row['allow_avatar'] != 1)
                 {
                         $SF->error('هذه الخاصية معطلة');
                 }
                 if ($_GET['main'] == 1)
                 {

                     if (!isset($_GET['page']) OR $_GET['page'] < 1)
                     {
                         $_GET['page'] = 1;
                     }

                     $page  = intval($_GET['page']);
                     $start = ($info_row['avatar_perpage'] * ($page-1));

                     $RP = new Pager($page);

                     $avatar_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "avater ORDER BY id DESC  LIMIT $start," . $info_row['avatar_perpage'] ."");

                     $avatars_row = array();
                     while ($avatar_row = $DB->sql_fetch_array($avatar_query))
                     {
                         $avatars_row[] = $avatar_row;
                         $Smarty->assign('avatars_row',$avatars_row);
                     }

                     $RP->SetPagerN($info_row['avatar_perpage'],$DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "avater")));

                     $Smarty->display('usercp_menu.tpl');
                     $Smarty->display('usercp_avatar.tpl');

                     print $RP->PageNum('cp=1&avatar=1&main=1');
			 		 $SF->FastMove();
                     $Smarty->display('footer.tpl');
                 }

                 if ($_GET['start'] == 1)
                 {
                     ## No Avatar
                     if ($_POST['SA'] == 'X0')
                     {
                         if (file_exists($member_row['avater_path']))
                         {
                             unlink($member_row['avater_path']);
                         }

                         $update_avatar = $DB->sql_query("UPDATE " . $db_prefix . "member SET avater_path='' WHERE username='".$SF->SafeSQL($member_row['username'])."'");
                         if ($update_avatar)
                         {
							$Smarty->assign('msgg','تم التحديث بنجاح !'); 
							$Smarty->assign('GO','usercp.php?cp=1&avatar=1&main=1');
							$SF->go_to('usercp.php?cp=1&avatar=1&main=1',2);             
							$Smarty->display('loading.tpl');

                             $Smarty->display('footer.tpl');
                         }
                     }

                     ## From The Site
                     if ($_POST['SA'] == 'X1')
                     {
                         if ($_POST['R1'] != 'V1')
                         {
                             if (strstr($_POST['R1'],'"'))
                             {
                                 $SF->error('المعذرة، عنوان الصورة يحتوي على رموز غير مسموح بها');
                             }

                             $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET avater_path='" . $_POST['R1'] . "' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");
                             if ($update)
                             {
								$Smarty->assign('msgg','تم التحديث بنجاح !'); 
								$Smarty->assign('GO','usercp.php?cp=1&avatar=1&main=1');
								$SF->go_to('usercp.php?cp=1&avatar=1&main=1',2);             
								$Smarty->display('loading.tpl');
								
                                $Smarty->display('footer.tpl');
                             }
                         }
                         else
                         {
                             $SF->error('عفواً، لم تختر صورة');
                         }
                     }

                     ## From Other Site
                     if ($_POST['SA'] == 'X2')
                     {
                         if (!empty($_POST['T1']))
                         {
                             $imagesize = @getimagesize('' . $_POST['T1'] . '');

                             if ($imagesize[0] > $info_row['max_avatar_width'])
                             {
                                 $SF->error('المعذره , لقد تعديت حجم العرض المسموح لك , يرجى اختيار صوره اصغر');
                             }

                             if ($imagesize[1] > $info_row['max_avatar_height'])
                             {
                                 $SF->error('المعذره , لقد تعديت حجم الارتفاع المسموح لك , يرجى اختيار صوره اصغر');
                             }


                             $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET avater_path='" . $_POST['T1'] . "' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");
                             if ($update)
                             {
								$Smarty->assign('msgg','تم التحديث بنجاح !'); 
								$Smarty->assign('GO','usercp.php?cp=1&avatar=1&main=1');
								$SF->go_to('usercp.php?cp=1&avatar=1&main=1',2);             
								$Smarty->display('loading.tpl');
                                 $Smarty->display('footer.tpl');
                             }
                         }
                         else
                         {
                             $SF->error('عفوا... لم تختر صورة');
                         }
                     }

                     ## From PC
                     if ($_POST['SA'] == 'X3')
                     {
                         $userpic  = $_FILES['F1'];

                         $filename = $userpic['name'];
                         $filetmp  = $userpic['tmp_name'];
                         $filetype = $userpic['type'];
                         $filesize = $userpic['size'];

                         $picpath  = $info_row['download_path'].'/avatar/'.$filename;
                         if ($filetmp != '')
                         {
                             if ($info_row['upload_avatar'] != 1)
                             {
                                 $SF->error ('المعذره .. لا يمكنك استخدام هذه الخاصية');
                             }

                             $extension = $SF->Get_file_extension(htmlspecialchars($filename));

                             $extension_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "ex WHERE Ex='$extension'");
                             $checkex_row     = $DB->sql_fetch_array($extension_query);

                             if ($DB->sql_num_rows($extension_query) <= 0)
                             {
                                 $SF->error('امتداد الملف غير مسموح !');
                             }
                             else
                             {
                                 if ($filesize > ($checkex_row['max_size'] * 1024))
                                 {
                                     $SF->error('المعذره حجم الملف غير مقبول');
                                 }
                                 else
                                 {

                                 $image_extensions = array ('.jpg','.gif','.jpeg','.png','.bmp');
                                 if (!in_array ($extension,$image_extensions))
                                 {
                                     $SF->error('المعذرة الملف ليس صورة !!');
                                 }

                                 if (file_exists($picpath))
                                 {
                                     $filename = $extensionexplode[0].time().$extension;
                                 }
                                 else
                                 {
                                     $filename = $filename;
                                 }

                                 if (file_exists($member_row['avater_path']))
                                 {
                                     unlink($member_row['avater_path']);
                                 }
                               
								$upload = @move_uploaded_file ($filetmp, $picpath);
                                 if ($upload)
                                 {
                                 	
									 $picpath2  = $info_row['download_path'].'/avatar/'.$filename;
									 $avatar_size = @getimagesize($picpath2);
									 
									 if ($avatar_size[0] > $info_row['max_avatar_width'])
									 {
										 unlink($picpath2);
										 $SF->error('المعذرة .. عرض الصورة غير مقبول');
									 }

									 if ($avatar_size[1] > $info_row['max_avatar_height'])
									 {
										 unlink($picpath2);
										 $SF->error('المعذرة .. ارتفاع الصوره غير مقبول');
									 }
									
									 
                                     $update_avatar = $DB->sql_query("UPDATE " . $db_prefix . "member SET avater_path='$picpath' WHERE username='".$SF->SafeSQL($member_row['username'])."'");
                                     if ($update_avatar)
                                     {
                                    		$Smarty->assign('msgg','تم التحديث بنجاح !'); 
											$Smarty->assign('GO','usercp.php?cp=1&avatar=1&main=1');
											$SF->go_to('usercp.php?cp=1&avatar=1&main=1',2);             
											$Smarty->display('loading.tpl');

                                         $Smarty->display('footer.tpl');
                                     }
                                     else
                                     {
                                         $SF->error('حدث خطأ لم يتم تحميل الصورة');
                                     }
                                 }
                             }
                         }
                     }// End From PC
                     else
                     {
                         $SF->error('الرجاء اختيار الصورة ..');
                     }
                 }
             }
         }

         if ($_GET['options'] == 1)
         { 
			$SF->html_title_page('خياراتك الخاصة - (Powered By MySmartBB Universal)');
             if ($_GET['main'] == 1)
             {

                 if ($groupper_row['allow_see_offstyles'] == 1 )
                 {
                     $getstyle_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "style ORDER BY style_order ASC");
                 }
                 else
                 {
                     $getstyle_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "style WHERE style_on<>'0' ORDER BY style_order ASC");
                 }

                 $getstyle_rows = array();
                 while ($getstyle_row = $DB->sql_fetch_array($getstyle_query))
                 {
                     $getstyle_rows[] = $getstyle_row;
                     $Smarty->assign('getstyle_rows',$getstyle_rows);
                 }

                 $Smarty->display('usercp_menu.tpl');
                 $Smarty->display('usercp_setting.tpl');
			 	 $SF->FastMove();
                 $Smarty->display('footer.tpl');
             }

             if ($_GET['start'] == 1)
             {
			 
			 
#------------------------------------------------
				$da = $_POST['da'];
				$ma = $_POST['ma'];
				$ya = $_POST['ya'];
				$ca = "$da/$ma/$ya";
				$sa = "$da/$ma";
				$Smarty->assign('sa',$sa);
				$Smarty->assign('da',$da);
				$Smarty->assign('ma',$ma);
				$Smarty->assign('ya',$ya);
				$Smarty->assign('ca',$ca);
				#------------------------------------------------
				$d= date("j/n");
				$Smarty->assign('d',$d);
				
				$rec = $DB->sql_query("SELECT * FROM `" . $db_prefix . "member` WHERE bday ='$d'");
				
				while($row = $DB->sql_fetch_array($rec))
					{
						$BD[] = $row;
						$Smarty->assign('MBD', $BD);
					}
#------------------------------------------------			 
			 

				 $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET style='" . intval($_POST['D1']) . "',hide_online='" . $_POST['hidden_browse'] . "',user_time='" . $_POST['user_time'] . "',bday1= '$ca',bday= '$sa' ,send_allow='" . $_POST['send_allow'] . "', keepmeon='" . $_POST['keepmeon'] . "' WHERE id='" . $member_row['id'] . "'");
				 
                 if ($update)
                 {
					$Smarty->assign('msgg','تم التحديث بنجاح !'); 
					$Smarty->assign('GO','usercp.php?cp=1&options=1&main=1');
					$SF->go_to('usercp.php?cp=1&options=1&main=1',2);             
					$Smarty->display('loading.tpl');
					
                    $Smarty->display('footer.tpl');
                 }
             }
         }
     }

     if ($_GET['option'] == 1)
     {
         if ($_GET['reply'] == 1)
         { 
			$SF->html_title_page('المواضيع التي شاركت فيها - (Powered By MySmartBB Universal)');
             if ($_GET['main'] == 1)
             {

                 if (!isset($_GET['page']) OR $_GET['page'] < 1)
                 {
                     $_GET['page'] = 1;
                 }

                 $page  = intval($_GET['page']);
                 $start = ($info_row['perpage'] * ($page-1));

                 $RP = new Pager($page);

                 define('REPLY',1);

                 $lastreply_query = $DB->sql_query("SELECT DISTINCT subject_id FROM " . $db_prefix . "reply WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND delete_topic<>'1' AND keepmeon=1 ORDER BY id DESC  LIMIT $start," . $info_row['perpage'] ."");
                 $lastreply_num   = $DB->sql_num_rows($lastreply_query);

                 $RP->SetPagerN($info_row['perpage'],$DB->sql_num_rows($DB->sql_query("SELECT DISTINCT subject_id FROM " . $db_prefix . "reply WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND delete_topic<>'1' AND keepmeon=1")));

                 if ($lastreply_num != 0)
                 {
                     while ($lastreply_row = $DB->sql_fetch_array($lastreply_query))
                     {
                         $lastrsubject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . $lastreply_row['subject_id'] . "' AND delete_topic<>'1'");

                         if (!isset($lastrsubjects_row)){
                             $lastrsubjects_row = array();
                         }

                         while ($lastrsubject_row = $DB->sql_fetch_array($lastrsubject_query))
                         {
                             $lastrsubjects_row[] = $lastrsubject_row;
                             $Smarty->assign('lastrsubjects_row',$lastrsubjects_row);
                             if ($lastrsubject_row['reply_number'] > 0)
                             {
                                 $reply_q = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE delete_topic<>'1' and subject_id='" . $lastrsubject_row['id'] . "' order by id DESC LIMIT 1");
                                 $reply_r = $DB->sql_fetch_array($reply_q);

                                 $reply_r2[] = $reply_r;
                                 $Smarty->assign("reply_r2",$reply_r2);

                                 $replier_q = $DB->sql_query("SELECT * FROM " . $db_prefix . "member where username='" . $reply_r['writer'] . "'");

                                 $replier_r[] = $DB->sql_fetch_array($replier_q);
                                 $Smarty->assign("replier_r",$replier_r);
                             }
                         }
                     }
                 }
                 else
                 {
                     $Smarty->assign('NoReply',1);
                 }

                 $Smarty->assign('print_page',$RP->PageNum('option=1&reply=1&main=1'));
                 $Smarty->display('usercp_menu.tpl');
                 $Smarty->display('usercp_show-replies-and-subjects.tpl');
			 	 $SF->FastMove();
                 $Smarty->display('footer.tpl');
             }
         }

         if ($_GET['subject'] == 1)
         { 
			$SF->html_title_page('المواضيع التي قمت بكتابتها - (Powered By MySmartBB Universal)');
             if ($_GET['main'] == 1)
             {

                      if (!isset($_GET['page']) OR $_GET['page'] < 1)
                      {
                          $_GET['page'] = 1;
                      }

                      $page  = intval($_GET['page']);
                      $start = ($info_row['perpage'] * ($page-1));

                      $RP = new Pager($page);

                 $RP->SetPagerN($info_row['perpage'],$DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE writer='" . $SF->SafeSQL($member_row['username']) . "'  AND delete_topic<>'1'")));

                 define('SUBJECT',1);

                 $subject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND delete_topic<>'1' ORDER BY id DESC LIMIT $start," . $info_row['perpage'] ."");
                 $subject_num   = $DB->sql_num_rows($subject_query);

                 if ($subject_num != 0)
                 {
                     $subjects_row = array();
                     while ($subject_row = $DB->sql_fetch_array($subject_query))
                     {
                         $subjects_row[] = $subject_row;
                         $Smarty->assign('subjects_row',$subjects_row);
                         if ($subject_row['reply_number'] > 0)
                         {
                             $reply_q = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE delete_topic<>'1' and subject_id='" . $subject_row['id'] . "' order by id DESC LIMIT 1");
                             $reply_r = $DB->sql_fetch_array($reply_q);

                             $reply_r2[] = $reply_r;
                             $Smarty->assign("reply_r2",$reply_r2);

                             $replier_q = $DB->sql_query("SELECT * FROM " . $db_prefix . "member where username='" . $reply_r['writer'] . "'");

                             $replier_r[] = $DB->sql_fetch_array($replier_q);
                             $Smarty->assign("replier_r",$replier_r);
                         }
                     }
                 }
                 else
                 {
                     $Smarty->assign('NoSubject',1);
                 }

                 $Smarty->assign('print_page',$RP->PageNum('option=1&subject=1&main=1'));

                 $Smarty->display('usercp_menu.tpl');
                 $Smarty->display('usercp_show-replies-and-subjects.tpl');
			 	 $SF->FastMove();
                 $Smarty->display('footer.tpl');
             }
         }

     if ($_GET['userwelcome'] == 1)
	  {
        $SF->html_title_page('اعداداتك الترحيب الشخصي - (Powered By MySmartBB Universal)');
		
      if ($_GET['main'] == 1)
	   	{
        	$user_welcome = str_replace('<br>','',$member_row['user_welcome']);

        	$Smarty->assign('user_welcome',$user_welcome);
        	$Smarty->display('usercp_menu.tpl');
      		$Smarty->display('usercp_mwelcome.tpl');
			$SF->FastMove();
        	$Smarty->display('footer.tpl');
      	}
	  
      if ($_GET['start'] == 1)
	   	{
       $user_welcome = nl2br($_POST['S1']);	
       $update = $DB->sql_query("UPDATE MySBB_member SET user_welcome='" . $user_welcome . "' WHERE username='" . $SF->SafeSQL($member_row['username']) . "'");
       if ($update)
	    	{
				$Smarty->assign('msgg','تم تحديث الرسالة بنجاح'); 
				$Smarty->assign('GO','usercp.php?option=1&options=1&main=1');
				$SF->go_to('usercp.php?option=1&userwelcome=1&main=1',2);             
				$Smarty->display('loading.tpl');
        	}
      	}
     }


         if ($_GET['attach'] == 1)
         {
		     $SF->html_title_page('مرفقاتك الشخصية - (Powered By MySmartBB Universal)');
             if ($_GET['main'] == 1)
             {
                 if (!isset($start))
                 {
                     $start = 0;
                 }
                 else
                 {
                     $page = intval( $_GET['start'] );
                 }

                 $page = intval( $_GET['page'] );

                 $RP = new Pager($start,$page); #Pager class by rafia

                 $RP->SetPagerN($info_row['perpage'],$DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "attach WHERE u_id='" . $member_row['id'] . "'")));

                 $getattach_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "attach WHERE u_id='" . $member_row['id'] . "' ORDER BY id DESC LIMIT $start," . $info_row['perpage'] ."");
                 $getattach_num = $DB->sql_num_rows($getattach_query);
                 if ($getattach_num != 0)
                 {
                     while ($getattach_row = $DB->sql_fetch_array($getattach_query))
                     {
                         if ($getattach_row['reply'] != 1)
                         {
                             $getattach_s_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . $getattach_row['subject_id'] . "'");
                             $getattach_s_row = $DB->sql_fetch_array($getattach_s_query);
                             $getattach_row['subject_title'] = $getattach_s_row['title'];
                         }
                         else
                         {
                             $getattach_r_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE id='" . $getattach_row['subject_id'] . "'");
                             $getattach_r_row = $DB->sql_fetch_array($getattach_r_query);

                             $getattach_row['reply_title'] = $getattach_r_row['title'];

                             $getattach_s_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . $getattach_r_row['subject_id'] . "'");
                             $getattach_s_row = $DB->sql_fetch_array($getattach_s_query);

                             $getattach_row['subject_title'] = $getattach_s_row['title'];
                         }
                         $getattach_rows[] = $getattach_row;
                         $Smarty->assign_by_ref('getattach_row',$getattach_rows);
                     }
                 }

                 $Smarty->assign('getattach_num',$getattach_num);
                 $Smarty->assign('print_page',$RP->PageNum('option=1&attach=1&main=1'));
                 $Smarty->display('usercp_menu.tpl');
                 $Smarty->display("usercp_attachments.tpl");
				 $SF->FastMove();
                 $Smarty->display("footer.tpl");
             }

             if ($_GET['del'] == 1)
             {
                 $At_D = $_POST['attach_id'];
                 if (count($At_D) == 0)
                 {
                     $SF->error("هنالك خطأ في المدخلات");
                 }

                 foreach ($At_D AS $id)
                 {
                     $del = $DB->sql_query("delete FROM " . $db_prefix . "attach where id='" . intval($id) . "' and u_id='" . $member_row['id'] . "'");
                     $del2 = @unlink($get_d_a_row['filepath']);
					 $del3 = @unlink($get_d_a_row['fileext']);
					 $del4 = @unlink($get_d_a_row['filename']);

					$Smarty->assign('msgg','تم حذف الملفات بنجاح'); 
					$Smarty->assign('GO','usercp.php?option=1&attach=1&main=1');
					$SF->go_to('usercp.php?option=1&attach=1&main=1',2);             
					$Smarty->display('loading.tpl');

                     $Smarty->display("footer.tpl");
                 }
             }
         }
     }

     
   if ($_GET['subscribe'] == 1)
	{
		if ($_GET['main'] == 1)
			{			
				$SF->html_title_page('التبليغ البريدي - (Powered By MySmartBB Universal)');
				$subject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND subscribe='1'");
				$subject_num = $DB->sql_num_rows($subject_query);
				if ($subject_num < 1)
				{
					$Smarty->assign('sub_subjects',0);
				}
				else
				{
					$Smarty->assign('sub_subjects',1);
					$subject_row = array();
					while ($subject_rows = $DB->sql_fetch_array($subject_query))
					{
						$subject_row[] = $subject_rows;
						$Smarty->assign('subject_row',$subject_row);
					}
				}
				
				$reply_query = $DB->sql_query("SELECT DISTINCT subject_id FROM " . $db_prefix . "reply WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND subscribe='1'");
				$reply_num = $DB->sql_num_rows($reply_query);
				if ($reply_num < 1)
				{
					$Smarty->assign('sub_reply',0);
				}
				else
				{
					$Smarty->assign('sub_reply',1);
					$subject_title = array();
					while ($reply_rows = $DB->sql_fetch_array($reply_query))
					{
						$subject_title_query = $DB->sql_query("SELECT * FROM " . $db_prefix  . "subject WHERE id='" . $reply_rows['subject_id'] . "'");
						$subject_title_row = $DB->sql_fetch_array($subject_title_query);
						$subject_title[] = $subject_title_row;
						$Smarty->assign('subject_title_row',$subject_title);
					}
				}
                $Smarty->display('usercp_menu.tpl');
                $Smarty->display('usercp_show-subscribe.tpl');
			 	$SF->FastMove();
				$Smarty->display('footer.tpl');
			}

	}

	if ($_GET['unsubscribe'] == 1)
	{
		$SF->html_title_page('التبليغ البريدي - (Powered By MySmartBB Universal)');
		if ($_GET['subject'] == 1)
		{
			$id = intval($_GET['s_id']);
			$sub_query = $DB->sql_query("SELECT * FROM " . $db_prefix ."subject WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND id='" . $id . "' AND subscribe='1'");
			$sub_num = $DB->sql_num_rows($sub_query);
			if ($sub_num < 1)
			{
				$SF->error('عُذراً , ولكن الموضوع الموضوع لست مُشتركاً به');
			}
			else
			{
				$unsub = $DB->sql_query("UPDATE " . $db_prefix  ."subject SET subscribe='0' WHERE id='" . $id . "'");
				if ($unsub)
				{
					$Smarty->assign('msgg','تم إلغاء الإشتراك'); 
					$Smarty->assign('GO','usercp.php?option=1&subscribe=1&main=1');
					$SF->go_to('usercp.php?option=1&subscribe=1&main=1',2);            
					$Smarty->display('loading.tpl');

					$Smarty->display('footer.tpl');
				}
				else
				{
					$SF->error('حدث خطأ');
				}
			}
		}
		if ($_GET['reply'] == 1)
		{
			$id = intval($_GET['s_id']);
			$sub_query = $DB->sql_query("SELECT * FROM " . $db_prefix ."reply WHERE writer='" . $SF->SafeSQL($member_row['username']) . "' AND subject_id='" . $id . "' AND subscribe='1'");
			$sub_num = $DB->sql_num_rows($sub_query);
			if ($sub_num < 1)
				{
					$SF->error('عُذراً , ولكن الموضوع الموضوع لست مُشتركاً به');
				}
				else
				{
					$unsub = $DB->sql_query("UPDATE " . $db_prefix  ."reply SET subscribe='0' WHERE subject_id='" . $id . "' AND writer='" . $SF->SafeSQL($member_row['username']) . "'");
					if ($unsub)
					{
						$Smarty->assign('msgg','تم إلغاء الإشتراك'); 
						$Smarty->assign('GO','usercp.php?option=1&subscribe=1&main=1');
						$SF->go_to('usercp.php?option=1&subscribe=1&main=1',2);            
						$Smarty->display('loading.tpl');

						$Smarty->display('footer.tpl');
		               
					}
					else
					{
						$SF->error('حدث خطأ');
					}


				}
		}

		

	}
 }
 else
 {
		$SF->html_title_page('لوحة التحكم - (Powered By MySmartBB Universal)');
		$SF->error('غير مسموح لك بالدخول لهذه الصفحة');
  }
?>